import { leasePartialDetail,submitLeasePartial} from "../../../api/order";
Page({
  data: {
    orderId: '',
    leaseId:'',
    partialAmount:0,
    infoData: {},
    checked: false,
    showState: false
  },
  getData() {
    leasePartialDetail({orderId:this.data.orderId,leaseId:this.data.leaseId}).then(res => {
      this.setData({
        infoData: res || {}
      })
      this.setData({ partialAmount: res.lease_total_amount })
    })
  },
  submit() {
    const { leaseId, orderId ,partialAmount} = this.data;
    submitLeasePartial({orderId:orderId,leaseId:leaseId,partialAmount:partialAmount}).then(res => {
      if (res.trade_no) {
        my.tradePay({
          tradeNO: res.trade_no,
          success: (res) => {
            console.log('aa');
            if (res.resultCode == 9000) {
              my.navigateBack();
            } else {
              my.showToast({
                type: 'fail',
                content: '支付失败，请稍后重试',
                duration: 1000,
              });
            }
          }
        });
      }
    })
  },
  checkedChange(e) {
    const { value } = e.detail;
    this.setData({ checked: value });
  },
  openState() {
    this.setData({ showState: true });
  },
  closeModal() {
    this.setData({ showState: false });
  },
  onLoad(options) {
    this.setData({ orderId: options.orderId });
    this.setData({ leaseId: options.leaseId });
  },
  onBack(e) {
    this.setData({ partialAmount: e.detail.value })
  },
  onShow() {
    this.getData();
  }
});
